<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>route-test</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

</head>
<body>
<div id="app"></div>
<script>
    const NotFound = {template: '<p>Page not found</p>'}
    const Home = {template: '<p>home page</p>'}
    const About = {template: '<p>about page</p>'}


    const app = new Vue({
        el: '#app',
        data: {
            currentRoute: window.location.pathname
        },
        computed: {
            ViewComponent() {
                const matchingView = new VueRouter([this.currentRoute])
                return matchingView
                    ? require('./pages/' + matchingView + '.vue')
                    : require('./pages/404.vue')
            }
        },
        render(h) {
            return h(this.ViewComponent)
        }
    })

    window.addEventListener('popstate', () => {
        app.currentRoute = window.location.pathname
    })
</script>
</body>
</html>